import 'dart:convert';

import 'package:flutter/foundation.dart';

import 'antenna_info.dart';


//工具柜信息
class ToolKit {
  String id;
  String toolKitName;
  String storageId;
  List<AntennaInfo> antennaList;
  int gpo;
  int gpi;
  ToolKit({
    required this.id,
    required this.toolKitName,
    required this.storageId,
    required this.antennaList,
    required this.gpo,
    required this.gpi,
  });

  ToolKit copyWith({
    String? id,
    String? toolKitName,
    String? storageId,
    List<AntennaInfo>? antennaList,
    int? gpo,
    int? gpi
  }) {
    return ToolKit(
      id: id ?? this.id,
      toolKitName: toolKitName ?? this.toolKitName,
      storageId: storageId ?? this.storageId,
      antennaList: antennaList ?? this.antennaList,
      gpo: gpo??this.gpo,
      gpi:gpi??this.gpi
    );
  }

  Map<String, dynamic> toMap() {
    return {
      'id': id,
      'toolKitName': toolKitName,
      'storageId': storageId,
      'gpo':gpo,
      'gpi':gpi,
      'antennaList': antennaList.map((x) => x.toMap()).toList(),
    };
  }

  factory ToolKit.fromMap(Map<String, dynamic> map) {
    return ToolKit(
      id: map['id'] ?? '',
      toolKitName: map['toolKitName'] ?? '',
      storageId: map['storageId'] ?? '',
      gpo: map['gpo']??0,
      gpi:map['gpi']??0,
      antennaList: List<AntennaInfo>.from(
          map['antennaList']?.map((x) => AntennaInfo.fromMap(x))),
    );
  }

  String toJson() => json.encode(toMap());

  factory ToolKit.fromJson(String source) =>
      ToolKit.fromMap(json.decode(source));

  @override
  String toString() {
    return 'ToolKit(id: $id, toolKitName: $toolKitName, storageId: $storageId, antennaList: $antennaList)';
  }

  @override
  bool operator ==(Object other) {
    if (identical(this, other)) return true;

    return other is ToolKit &&
        other.id == id &&
        other.toolKitName == toolKitName &&
        other.storageId == storageId &&other.gpo==gpo&&
        listEquals(other.antennaList, antennaList);
  }

  @override
  int get hashCode {
    return id.hashCode ^
        toolKitName.hashCode ^
        storageId.hashCode ^
        gpo.hashCode^
        antennaList.hashCode;
  }
}
